package com.example.test.carousel;

import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    private ViewPager vpLoans;
    List<Integer> mListImages = new ArrayList<>();
    private ViewPagerAdapter mViewPagerAdapter;
    private List<View> mViews = new ArrayList<View>(); //数据源

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        vpLoans = (ViewPager)findViewById(R.id.ViewPager);
        mListImages.add(R.mipmap.temp1);
        mListImages.add(R.mipmap.temp2);
        mListImages.add(R.mipmap.temp3);
        mListImages.add(R.mipmap.temp2);
        mListImages.add(R.mipmap.temp1);
        mViews.clear();
        for (int i = 0; i < 5; i++) {
            mViews.add(getViewPagerView(mListImages.get(i)));
        }
        mViewPagerAdapter=new ViewPagerAdapter(mViews);
        vpLoans.setPageTransformer(true, new HeadViewPagerTransformer());
        vpLoans.setOffscreenPageLimit(3);
        vpLoans.setAdapter(mViewPagerAdapter);
    }



    public View getViewPagerView(int url){
        ImageView mImageView;
        View view = View.inflate(this, R.layout.mainimage_item, null);
        mImageView= (ImageView) view.findViewById(R.id.image);
        mImageView.setImageResource(url);
        return view;
    }

}
